//
//  visitorTableViewController.swift
//  weibo
//
//  Created by Qing on 2017/5/1.
//  Copyright © 2017年 成哥哥. All rights reserved.
//

import UIKit


/// 访问 和 用户 -> 切的标注。
class visitorTableViewController: UITableViewController {

//    访客视图界面切的标志。
    var visitorViews: visitorView?
    
    /// 用户访问标识
    fileprivate var usrVisitor = UserAccountViewModel.sharedUserAccount.userLogon
    
    override func loadView() { 
        
        usrVisitor ? super.loadView() : setupVisitorView()
        
    }
    
    /// 设置访客视图
    fileprivate func setupVisitorView() {
        
        visitorViews = visitorView()
        
        view = visitorViews
        
//        在导航条添加登录和注册按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: "visitorViewLogin")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: "visitorViewRegister")
        
//        监听事件
//        visitorViews?.loginBtn.addTarget(self, action: Selector("visitorViewLogin"), for: UIControlEvents.touchUpInside)
        visitorViews?.registerBtn.addTarget(self, action: "visitorViewRegister", for: UIControlEvents.touchUpInside)
        visitorViews?.loginBtn.addTarget(self, action: Selector.init("visitorViewLogin"), for: UIControlEvents.touchUpInside)
        
    }
}

//MARK: - 监听动作
extension visitorTableViewController {
    
    
    /// 监听导航注册动作
    func visitorViewRegister() {
        print("注册")
    }
    
    ///监听导航登录动作
    func visitorViewLogin() {
            print("登录")
        
        let vc = OAuthViewController()
        
        let nav = UINavigationController(rootViewController: vc)
        
        present(nav, animated: true, completion: nil)
        
        
    }
}
